﻿
const { createApp, ref, onMounted, h, reactive, toRefs, getCurrentInstance, toRaw, defineProps, defineEmits, unref, computed, watch  } = Vue;
function camelToHyphen(str) {
    // 将驼峰命名转换为连字符分隔的小写字符串
    return 'a-' + str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
}
function mcamelToHyphen(str) {
    // 将驼峰命名转换为连字符分隔的小写字符串
    return 'm-' + str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
}
var croute = ""
const singalApp = (controllerName, manage, locale) => {

    // 定义 vue3 的对象
    const Composition = {

   
        setup() {
            var Params = {

            }
           
            watch(() => window.location.href, (n) => {
                croute=n
            }, {
                deep: true, immediate: true
            })



            if (getCurrentInstance()) {
                const { proxy } = getCurrentInstance()
                Params[controllerName + 'Params'] = manage(proxy)
            } else {
                Params[controllerName + 'Params'] = manage()
            }

            const vlocale = locale
            Params[controllerName + 'Params'].vvback=()=>{
               vback()
             }
            onMounted(() => {
                if (Params[controllerName + 'Params'].init) {
                    Params[controllerName + 'Params'].init()
                }
                if (Params[controllerName + 'Params'].mounted) {
                    Params[controllerName + 'Params'].mounted()
                }
            })

            for (let e in Params[controllerName + 'Params'].template) {
      
                let str = mcamelToHyphen(e)
          
                vapp.component(str, Params[controllerName + 'Params'].template[e]);
            }


          
            return { // 返回对象给模板
                ...Params,
                vlocale
            }
        }
    }
    const vapp = createApp(Composition);
    for (let e in antd) {
   
        let str = camelToHyphen(e)
        if (str == "a-theme") {

        } else {
            vapp.component(str, antd[e]);
        }

     

    }

    vapp.config.errorHandler = (err) => {
        console.log(err, 'err')
        /* 处理错误 */
    }
    vapp.mount(`#`+controllerName);
}

